<?php

declare(strict_types=1);
namespace App\Controller;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\ResponseInterface;
use App\Service\MchantService;
#[AutoController]
class MchantController
{
    #[Inject]
    private MchantService $mchantService;
    public function login(RequestInterface $request, ResponseInterface $response)
    {
        // 从请求中获得 id 参数
        $mobile = $request->input("mobile","");
        $pwd = $request->input("password","");
        # 查询用户
        $rec = $this->mchantService->get_mchant_user([
            "mobile"=>$mobile,
            "password"=>$pwd,
        ]);
        return $rec;

    }

    public function order_info(RequestInterface $request, ResponseInterface $response){
        # 订单详情
        $order_no = $request->input("order_no","");
        $mchant_id = $request->input("mchant_id","");
        $rec = $this->mchantService->get_order_info($order_no);
        return $rec;
    }

    public function order_list(RequestInterface $request, ResponseInterface $response){
        # 订单详情
        $mchant_id = $request->input("mchant_id","");
        $page = $request->input("page","1");
        $mchant_id = (int)$mchant_id;
        $page = (int)$page;
        $rec = $this->mchantService->get_order_list($mchant_id,$page);
        return $rec;
    }

    public function cancel_order(RequestInterface $request, ResponseInterface $response){
        # 核销用户
        $order_no = $request->input("order_no","");
        $mchant_id = $request->input("mchant_id","");
        if (empty($order_no) or empty($mchant_id)){
            return [
                "code"=>20063,
                "message"=>"参数错误！",
                "content"=>(object)[]
            ];
        }else{
            $mchant_id = (int)$mchant_id;
            $rec = $this->mchantService->cancel($mchant_id,$order_no);
            return $rec;
        }

    }

    public function test(RequestInterface $request)
    {
        // 从请求中获得 id 参数
        $id = $request->input('id', 1);
        return (string)$id;
    }
}